﻿/*
Post-Deployment Script Template							
--------------------------------------------------------------------------------------
 This file contains SQL statements that will be appended to the build script.		
 Use SQLCMD syntax to include a file in the post-deployment script.			
 Example:      :r .\myfile.sql								
 Use SQLCMD syntax to reference a variable in the post-deployment script.		
 Example:      :setvar TableName MyTable							
			   SELECT * FROM [$(TableName)]					
--------------------------------------------------------------------------------------
*/


-- LOAD Request Status
-- This maps directly into the VMFactory.Api.Business.Entity.RequestStatus enumeration

/*

To regenerate this script use the following command

USE [VMFSupport]
GO

SELECT 
'
UPDATE 
	[dbo].[RequestStatus] 
SET
	[Name] = ''' + [Name] + ''',
	[Description] = '''  + [Description] + ''',
	[StepSequence] = ' + CAST([StepSequence] AS VARCHAR(10)) + '
WHERE
	[Id] = ' + CAST([Id] AS VARCHAR(10)) + '

IF @@ROWCOUNT <> 1 
BEGIN
	
	SET IDENTITY_INSERT [dbo].[RequestStatus] ON

	INSERT
	INTO 
		[dbo].[RequestStatus] 
		([Id], [Name], [Description], [StepSequence])
	VALUES
		(' + CAST([Id] AS VARCHAR(10)) + ', ''' + [Name] + ''', '''  + [Description] + ''', ' + CAST([StepSequence] AS VARCHAR(10)) + ')

	SET IDENTITY_INSERT [dbo].[RequestStatus] OFF

END

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
'
  FROM [dbo].[RequestStatus]
GO


*/

UPDATE 
	[dbo].[RequestStatus] 
SET
	[Name] = 'None',
	[Description] = 'No Status',
	[StepSequence] = 0
WHERE
	[Id] = 1

IF @@ROWCOUNT <> 1 
BEGIN
	
	SET IDENTITY_INSERT [dbo].[RequestStatus] ON

	INSERT
	INTO 
		[dbo].[RequestStatus] 
		([Id], [Name], [Description], [StepSequence])
	VALUES
		(1, 'None', 'No Status', 0)

	SET IDENTITY_INSERT [dbo].[RequestStatus] OFF

END

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

UPDATE 
	[dbo].[RequestStatus] 
SET
	[Name] = 'Queued',
	[Description] = 'Has been picked up and queued for processing',
	[StepSequence] = 1
WHERE
	[Id] = 2

IF @@ROWCOUNT <> 1 
BEGIN
	
	SET IDENTITY_INSERT [dbo].[RequestStatus] ON

	INSERT
	INTO 
		[dbo].[RequestStatus] 
		([Id], [Name], [Description], [StepSequence])
	VALUES
		(2, 'Queued', 'Has been picked up and queued for processing', 1)

	SET IDENTITY_INSERT [dbo].[RequestStatus] OFF

END

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

UPDATE 
	[dbo].[RequestStatus] 
SET
	[Name] = 'In progress',
	[Description] = 'Has been picked from the queue and started processing',
	[StepSequence] = 200
WHERE
	[Id] = 3

IF @@ROWCOUNT <> 1 
BEGIN
	
	SET IDENTITY_INSERT [dbo].[RequestStatus] ON

	INSERT
	INTO 
		[dbo].[RequestStatus] 
		([Id], [Name], [Description], [StepSequence])
	VALUES
		(3, 'In progress', 'Has been picked from the queue and started processing', 200)

	SET IDENTITY_INSERT [dbo].[RequestStatus] OFF

END

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

UPDATE 
	[dbo].[RequestStatus] 
SET
	[Name] = 'Installation Completed',
	[Description] = 'Processing has terminated with no error',
	[StepSequence] = 300
WHERE
	[Id] = 4

IF @@ROWCOUNT <> 1 
BEGIN
	
	SET IDENTITY_INSERT [dbo].[RequestStatus] ON

	INSERT
	INTO 
		[dbo].[RequestStatus] 
		([Id], [Name], [Description], [StepSequence])
	VALUES
		(4, 'Installation Completed', 'Processing has terminated with no error', 300)

	SET IDENTITY_INSERT [dbo].[RequestStatus] OFF

END

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

UPDATE 
	[dbo].[RequestStatus] 
SET
	[Name] = 'Packing',
	[Description] = 'Packing has started',
	[StepSequence] = 400
WHERE
	[Id] = 5

IF @@ROWCOUNT <> 1 
BEGIN
	
	SET IDENTITY_INSERT [dbo].[RequestStatus] ON

	INSERT
	INTO 
		[dbo].[RequestStatus] 
		([Id], [Name], [Description], [StepSequence])
	VALUES
		(5, 'Packing', 'Packing has started', 400)

	SET IDENTITY_INSERT [dbo].[RequestStatus] OFF

END

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

UPDATE 
	[dbo].[RequestStatus] 
SET
	[Name] = 'Packing Completed',
	[Description] = 'Packing has finished',
	[StepSequence] = 500
WHERE
	[Id] = 6

IF @@ROWCOUNT <> 1 
BEGIN
	
	SET IDENTITY_INSERT [dbo].[RequestStatus] ON

	INSERT
	INTO 
		[dbo].[RequestStatus] 
		([Id], [Name], [Description], [StepSequence])
	VALUES
		(6, 'Packing Completed', 'Packing has finished', 500)

	SET IDENTITY_INSERT [dbo].[RequestStatus] OFF

END

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

UPDATE 
	[dbo].[RequestStatus] 
SET
	[Name] = 'Deploying',
	[Description] = 'Deploying files to its pick up destination',
	[StepSequence] = 600
WHERE
	[Id] = 7

IF @@ROWCOUNT <> 1 
BEGIN
	
	SET IDENTITY_INSERT [dbo].[RequestStatus] ON

	INSERT
	INTO 
		[dbo].[RequestStatus] 
		([Id], [Name], [Description], [StepSequence])
	VALUES
		(7, 'Deploying', 'Deploying files to its pick up destination', 600)

	SET IDENTITY_INSERT [dbo].[RequestStatus] OFF

END

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

UPDATE 
	[dbo].[RequestStatus] 
SET
	[Name] = 'Deployed',
	[Description] = 'Deployed successful',
	[StepSequence] = 700
WHERE
	[Id] = 8

IF @@ROWCOUNT <> 1 
BEGIN
	
	SET IDENTITY_INSERT [dbo].[RequestStatus] ON

	INSERT
	INTO 
		[dbo].[RequestStatus] 
		([Id], [Name], [Description], [StepSequence])
	VALUES
		(8, 'Deployed', 'Deployed successful', 700)

	SET IDENTITY_INSERT [dbo].[RequestStatus] OFF

END

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

UPDATE 
	[dbo].[RequestStatus] 
SET
	[Name] = 'Ready',
	[Description] = 'Ready for pickup by the requester',
	[StepSequence] = 800
WHERE
	[Id] = 9

IF @@ROWCOUNT <> 1 
BEGIN
	
	SET IDENTITY_INSERT [dbo].[RequestStatus] ON

	INSERT
	INTO 
		[dbo].[RequestStatus] 
		([Id], [Name], [Description], [StepSequence])
	VALUES
		(9, 'Ready', 'Ready for pickup by the requester', 800)

	SET IDENTITY_INSERT [dbo].[RequestStatus] OFF

END

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

UPDATE 
	[dbo].[RequestStatus] 
SET
	[Name] = 'Garbage Collecting',
	[Description] = 'Garbage collecting started',
	[StepSequence] = 900
WHERE
	[Id] = 10

IF @@ROWCOUNT <> 1 
BEGIN
	
	SET IDENTITY_INSERT [dbo].[RequestStatus] ON

	INSERT
	INTO 
		[dbo].[RequestStatus] 
		([Id], [Name], [Description], [StepSequence])
	VALUES
		(10, 'Garbage Collecting', 'Garbage collecting started', 900)

	SET IDENTITY_INSERT [dbo].[RequestStatus] OFF

END

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

UPDATE 
	[dbo].[RequestStatus] 
SET
	[Name] = 'Garbage Collected',
	[Description] = 'Garbage collecting finished',
	[StepSequence] = 1000
WHERE
	[Id] = 11

IF @@ROWCOUNT <> 1 
BEGIN
	
	SET IDENTITY_INSERT [dbo].[RequestStatus] ON

	INSERT
	INTO 
		[dbo].[RequestStatus] 
		([Id], [Name], [Description], [StepSequence])
	VALUES
		(11, 'Garbage Collected', 'Garbage collecting finished', 1000)

	SET IDENTITY_INSERT [dbo].[RequestStatus] OFF

END

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

UPDATE 
	[dbo].[RequestStatus] 
SET
	[Name] = 'Flailed',
	[Description] = 'Processing has terminated with error',
	[StepSequence] = -100
WHERE
	[Id] = 100

IF @@ROWCOUNT <> 1 
BEGIN
	
	SET IDENTITY_INSERT [dbo].[RequestStatus] ON

	INSERT
	INTO 
		[dbo].[RequestStatus] 
		([Id], [Name], [Description], [StepSequence])
	VALUES
		(100, 'Flailed', 'Processing has terminated with error', -100)

	SET IDENTITY_INSERT [dbo].[RequestStatus] OFF

END

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
